package com.yanqu.road.entity.activity.newyearbag;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.enums.activity.newyearbag.eNewYearBagType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_s_activity_newyearbag_limit")
public class NewYearBagLimitConfig {

    @FieldTypeAnnotation(desc = "活动ID", select = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "用户级别")
    private int userLv;
    @FieldTypeAnnotation(desc = "用户区间")
    private int userCondition; // 最近充值金额

    @FieldTypeAnnotation(desc = "每日通宝限制")
    private List<Long> tongBaoDayLimit;
    @FieldTypeAnnotation(desc = "每日现金限制")
    private List<Long> cashDayLimit;
    @FieldTypeAnnotation(desc = "每日皮肤限制")
    private List<Long> skinDayLimit;

    @FieldTypeAnnotation(desc = "总通宝限制")
    private int tongBaoAllLimit;
    @FieldTypeAnnotation(desc = "总现金上限")
    private int cashAllLimit;
    @FieldTypeAnnotation(desc = "总皮肤上限")
    private long skinAllLimit;

    @FieldTypeAnnotation(desc = "通宝到达上限后权重变化")
    private String tongBaoChangeWeight;
    @FieldTypeAnnotation(desc = "现金达到上限后权重变化")
    private String cashChangeWeight;
    @FieldTypeAnnotation(desc = "皮肤达到上限后权重变化")
    private String skinChangeWeight;

    private Map<Integer, Integer> tongBaoChangeWeightMap;
    private Map<Integer, Integer> cashChangeWeightMap;
    private Map<Integer, Integer> skinChangeWeightMap;


    public long getAllLimit(eNewYearBagType type) {
        if (type == eNewYearBagType.TongBao) {
            return tongBaoAllLimit;
        } else if (type == eNewYearBagType.XianJin) {
            return cashAllLimit;
        } else if (type == eNewYearBagType.Skin) {
            return skinAllLimit;
        } else {
            return 0;
        }
    }

    public long getDayLimit(eNewYearBagType type, int day) {
        List<Long> list = new ArrayList<>();
        if (type == eNewYearBagType.TongBao) {
            list = tongBaoDayLimit;
        } else if (type == eNewYearBagType.XianJin) {
            list = cashDayLimit;
        } else if (type == eNewYearBagType.Skin) {
            list = skinDayLimit;
        }

        if (day > list.size()) {
            return 0;
        } else {
            return list.get(day - 1);
        }
    }

    public long getSumDayLimit(eNewYearBagType type, int day) {
        List<Long> list = new ArrayList<>();
        if (type == eNewYearBagType.TongBao) {
            list = tongBaoDayLimit;
        } else if (type == eNewYearBagType.XianJin) {
            list = cashDayLimit;
        } else if (type == eNewYearBagType.Skin) {
            list = skinDayLimit;
        }

        long sum = 0;
        for (int i = 0; i < list.size() && i < day; i++) {
            sum += list.get(i);
        }
        return sum;
    }


    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getUserLv() {
        return userLv;
    }

    public void setUserLv(int userLv) {
        this.userLv = userLv;
    }

    public int getUserCondition() {
        return userCondition;
    }

    public void setUserCondition(int userCondition) {
        this.userCondition = userCondition;
    }

    public List<Long> getTongBaoDayLimit() {
        return tongBaoDayLimit;
    }

    public void setTongBaoDayLimit(List<Long> tongBaoDayLimit) {
        this.tongBaoDayLimit = tongBaoDayLimit;
    }

    public List<Long> getCashDayLimit() {
        return cashDayLimit;
    }

    public void setCashDayLimit(List<Long> cashDayLimit) {
        this.cashDayLimit = cashDayLimit;
    }

    public List<Long> getSkinDayLimit() {
        return skinDayLimit;
    }

    public void setSkinDayLimit(List<Long> skinDayLimit) {
        this.skinDayLimit = skinDayLimit;
    }

    public int getTongBaoAllLimit() {
        return tongBaoAllLimit;
    }

    public void setTongBaoAllLimit(int tongBaoAllLimit) {
        this.tongBaoAllLimit = tongBaoAllLimit;
    }

    public int getCashAllLimit() {
        return cashAllLimit;
    }

    public void setCashAllLimit(int cashAllLimit) {
        this.cashAllLimit = cashAllLimit;
    }

    public long getSkinAllLimit() {
        return skinAllLimit;
    }

    public void setSkinAllLimit(long skinAllLimit) {
        this.skinAllLimit = skinAllLimit;
    }

    public String getTongBaoChangeWeight() {
        return tongBaoChangeWeight;
    }

    public void setTongBaoChangeWeight(String tongBaoChangeWeight) {
        Map<Integer, Integer> map = new ConcurrentHashMap<>();
        for (String tmpStr : StringUtils.stringToStringList(tongBaoChangeWeight, "\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(tmpStr, "=");
            if(list.size() == 2) {
                map.put(list.get(0), list.get(1));
            }
        }

        this.tongBaoChangeWeightMap = map;
        this.tongBaoChangeWeight = tongBaoChangeWeight;
    }

    public String getCashChangeWeight() {
        return cashChangeWeight;
    }

    public void setCashChangeWeight(String cashChangeWeight) {
        Map<Integer, Integer> map = new ConcurrentHashMap<>();
        for (String tmpStr : StringUtils.stringToStringList(cashChangeWeight, "\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(tmpStr, "=");
            if(list.size() == 2) {
                map.put(list.get(0), list.get(1));
            }
        }

        this.cashChangeWeightMap = map;
        this.cashChangeWeight = cashChangeWeight;
    }

    public String getSkinChangeWeight() {
        return skinChangeWeight;
    }

    public void setSkinChangeWeight(String skinChangeWeight) {
        Map<Integer, Integer> map = new ConcurrentHashMap<>();
        for (String tmpStr : StringUtils.stringToStringList(skinChangeWeight, "\\|")) {
            List<Integer> list = StringUtils.stringToIntegerList(tmpStr, "=");
            if(list.size() == 2) {
                map.put(list.get(0), list.get(1));
            }
        }

        this.skinChangeWeightMap = map;
        this.skinChangeWeight = skinChangeWeight;
    }

    // ---------------------------

    public Map<Integer, Integer> getTongBaoChangeWeightMap() {
        return tongBaoChangeWeightMap;
    }

    public Map<Integer, Integer> getCashChangeWeightMap() {
        return cashChangeWeightMap;
    }

    public Map<Integer, Integer> getSkinChangeWeightMap() {
        return skinChangeWeightMap;
    }

}
